package com.example.zyfypt_206shj.activity;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.zyfypt_206shj.R;
import com.example.zyfypt_206shj.bean.RegInfo;
import com.example.zyfypt_206shj.iface.RegListener;
import com.example.zyfypt_206shj.model.RegModel;

public class activity_regist extends Activity implements View.OnClickListener,RegListener{

    private Button button_reg, button_cancel;
    private EditText editText_username, editText_password, editText_phone;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_regist);
        init_regView();
    }

    private void init_regView(){
        button_reg = (Button) findViewById(R.id.reg);
        button_cancel = (Button) findViewById(R.id.cancel);
        editText_username = (EditText) findViewById(R.id.editText_usr);
        editText_password = (EditText) findViewById(R.id.editText_passwd);
        editText_phone = (EditText) findViewById(R.id.editText_tel);
        button_reg.setOnClickListener(this);
        button_cancel.setOnClickListener(this);
    }

    @Override
    public void onResponse(String result) {
        if((result+"").equals("1")){
            Toast.makeText(this, "注册成功！快去登陆吧！", Toast.LENGTH_SHORT).show();
        }else {
            Toast.makeText(this, "注册失败！", Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public void onFail(String msg) {
        Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
        Log.e("error",msg);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.reg:
                RegModel regModel = new RegModel();
                regModel.getRegInfo(editText_username.getText().toString(), editText_password.getText().toString(), editText_phone.getText().toString(), this);
                break;
            case R.id.cancel:
                activity_regist.this.finish();
                break;
            default:break;
        }
    }
}
